instruction
stringlengths
0
30k
How do I make a menu in python that does not require the user to press (enter) to make a selection?
|python|
I've got a menu in python. That part was easy. I'm using raw_input() to get the selection from the user. The problem is that raw_input (and input) require the user to press Enter after they make a selection. Is there any way to make the program act immediately upon a keystroke? Here's what I've got so far: i...
I've got a menu in python. That part was easy. I'm using raw_input() to get the selection from the user. The problem is that raw_input (and input) require the user to press Enter after they make a selection. Is there any way to make the program act immediately upon a keystroke? Here's what I've got so far: i...
I've got a menu in python. That part was easy. I'm using raw_input() to get the selection from the user. The problem is that raw_input (and input) require the user to press Enter after they make a selection. Is there any way to make the program act immediately upon a keystroke? Here's what I've got so far: i...
Dang -- lbrandy beat me to the punch, but that doesn't mean I can't provide you with the system results for Vista! >>> import os >>> print os.name nt >>> import platform >>> platform.system() 'Windows' >>> platform.release() 'Vista'
> Without the extra quotes around the input string parameter, the Javascript function thinks I'm passing in an integer. Can you do some rudimentary string function to force JavaScript into changing it into a string? Like value = value + ""
System.Windows.Forms.Cursor.Position
**C# 3.5** Without notifyicon, you will need to terminate this application in task manager using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { static class Program { static void Main() { Timer timer = ...
**for C# 3.5** without notifyicon therefore you will need to terminate this application in task manager manually using System; using System.Windows.Forms; static class Program { static void Main() { Timer timer = new Timer(); // timer.Interval =...
**for C# 3.5** without notifyicon therefore you will need to terminate this application in task manager manually using System; using System.Drawing; using System.Windows.Forms; static class Program { static void Main() { Timer timer = new Timer(); ...
Thanks all, for the record here's the results on Mac: <pre> >>> import os >>> os.name 'posix' >>> import platform >>> platform.system() 'Darwin' >>> platform.release() '8.11.1' </pre>
Try putting the extra text inside the server-side script block and concatenating. onclick='<%# "ToggleDisplay(""" & DataBinder.Eval(Container.DataItem, "JobCode") & """);" %>' Edit: I'm pretty sure you could just use double quotes outside the script block as well.
The reason msvcrt fails in IDLE is because IDLE is not accessing the library that runs msvcrt. Whereas when you run the program natively in cmd.exe it works nicely. For the same reason that your program blows up on Mac and Linux terminals. But I guess if you're going to be using this specifically for windows, more ...
Wow, that took forever. Ok, here's what I've ended up with #!C:\python25\python.exe import msvcrt print """Menu 1) Say Foo 2) Say Bar""" while 1: char = msvcrt.getch() if char == chr(27): #escape break if char == "1": print "foo" ...
Wow, that took forever. Ok, here's what I've ended up with #!C:\python25\python.exe import msvcrt print """Menu 1) Say Foo 2) Say Bar""" while 1: char = msvcrt.getch() if char == chr(27): #escape break if char == "1": print "foo" ...
I create folders named after the build versions and put upgrade and downgrade scripts in there. For example, you could have the following folders: 1.0.0, 1.0.1 and 1.0.2. Each one contains the script that allows you to upgrade or downgrade your database between versions. Should a client or customer call you with a p...
I had recently similar problem and the only way to solve it was to use plain old HTML codes for single (`&#34;`) and double quotes (`&#39;`) to escape it 3-times. Source code was total mess but it worked.
I had recently similar problem and the only way to solve it was to use plain old HTML codes for single (`&#34;`) and double quotes (`&#39;`). Source code was total mess of course but it worked. I don't know if I correctly understand your example, but try <a id="aShowHide" onclick='ToggleDisplay(&#34;<%# Da...
I had recently similar problem and the only way to solve it was to use plain old HTML codes for single (`&#34;`) and double quotes (`&#39;`). Source code was total mess of course but it worked. Try <a id="aShowHide" onclick='ToggleDisplay(&#34;<%# DataBinder.Eval(Container.DataItem, "JobCode") %>&#34;);'>S...
CSV File Imports in .Net
|c#|vb.net|file|csv|import|
I realize this is a newbie question, but I'm looking for a simple solution - it seems like there should be one. What's the best way to import a CSV file into a strongly-typed data structure? Again simple = better. Thanks.
Triple Quotes? How do I delimit a databound Javascript string parameter in ASP.NET?
|asp.net|javascript|anchor|display|single|quotes|
How do I delimit a Javascript databound string parameter in an anchor OnClick event? I have an anchor tag in an ASP.NET Repeater control. The OnClick event of the anchor contains a call to a Javascript function. The Javascript funciton takes a string for it's input parameter. The string parameter is populat...
|asp.net|javascript|anchor|quotes|
|asp.net|javascript|quotes|anchor|
How do I delimit a Javascript databound string parameter in an anchor OnClick event? - I have an anchor tag in an ASP.NET Repeater control. - The OnClick event of the anchor contains a call to a Javascript function. - The Javascript funciton takes a string for it's input parameter. - The string parameter is...
How do I delimit a Javascript databound string parameter in an anchor OnClick event? - I have an anchor tag in an ASP.NET Repeater control. - The OnClick event of the anchor contains a call to a Javascript function. - The Javascript funciton takes a string for it's input parameter. - The string parameter is...
Extending on what [Mike Powell][1] has to say, I am actually a big fan of almost all of the podcasts at [http://www.twit.tv][2]. Most of the content is watered down a bit, but some of the speakers are top notch thinkers - especially on "This Week in Tech", the flagship program. Oh - and Car Talk on NPR but those ...
Chris' probably has the best pure answer to the question: http://stackoverflow.com/questions/1104/#1109 However, I'm curious about the root of the question. If the user should *always* wrap the call in a try/catch block, should the user-called function really be throwing exceptions in the first place? This is a...
You are going to get a lot of strings, that's for sure... ![\sum_{i=x}^y{\frac{r!}{{(r-i)}!}}][1] Where, x and y is how you define them and r is the number of characters we are selecting from --if I am understanding you correctly. You should definitely generate these as needed and not get sloppy and say, generate...
If you can guarantee that there are no commas in the data, then the simplest way would probably be to use [String.split][1]. For example: String[] values = myString.Split(','); myObject.StringField = values[0]; myObject.IntField = Int32.Parse(values[1]); There may be libraries you could use to he...
A good simple way to do it is to open the file, and read each line into an array, linked list, data-structure-of-your-choice. Be careful about handling the first line though. This may be over your head, but there seems to be a direct way to access them as well using a [connection string][1]. Why not try using pyt...
A good simple way to do it is to open the file, and read each line into an array, linked list, data-structure-of-your-choice. Be careful about handling the first line though. This may be over your head, but there seems to be a direct way to access them as well using a [connection string][1]. Why not try using pyt...
I listen to the [javaposse][1] regularly, they cover mostly Java, but not solely. [1]: http://javaposse.com
Two articles on CodeProject that provide code for a solution, one that [uses SteamReader][1] and one that [imports CSV data][2] using the [Microsoft Text Driver][3]. [1]: http://www.codeproject.com/KB/database/CsvReader.aspx [2]: http://www.codeproject.com/KB/database/FinalCSVReader.aspx [3]: http://suppor...
the problem is that the sphere can be distorted a number of ways, and having all those points known on the equator, lets say, wont help you map points further away. You need better 'close' points, then you can assume these three points are on a plane with the fourth and do the interpolation. Without knowing the dis...
the problem is that the sphere can be distorted a number of ways, and having all those points known on the equator, lets say, wont help you map points further away. You need better 'close' points, then you can assume these three points are on a plane with the fourth and do the interpolation --knowing that the distan...
I'm not clear on whether or not you're wanting to add the asynchronous bits to the server in C# or the client in C++. If you're talking about doing this in C++, desktop Windows platforms can do socket I/O asynchronously through the API's that use overlapped I/O. For sockets, WSASend, WSARecv both allow async I/O (r...
Ummm. Maybe I am missing something about the question here, but if you have long/lat info, you also have the direction of north? It seems you need to map Cartesian coordinates to a geodesic coordinates system. For example wgs84 is oblated spheroid if I remember correctly. The maths involved is non-trivial, but t...
Ummm. Maybe I am missing something about the question here, but if you have long/lat info, you also have the direction of north? It seems you need to map geodesic coordinates to a projected coordinates system. For example osgb to wgs84. The maths involved is non-trivial, but the code comes out a only a few lines...
Use SVN Revision to label build in CCNET
|cruisecontrol.net|svn|msbuild|
I am using CCNET on a sample project with SVN as my source control. CCNET is configured to create a build on every check in. CCNET uses MSBuild to build the source code. I would like to use the latest revision number to generate AssemblyInfo.cs while compiling. How can I retrieve the latest revision from subversion...
|svn|msbuild|cruisecontrol.net|
I am using CCNET on a sample project with SVN as my source control. CCNET is configured to create a build on every check in. CCNET uses MSBuild to build the source code. I would like to use the latest revision number to generate AssemblyInfo.cs while compiling. How can I retrieve the latest revision from subversion...
Here is some sample code. I think this is what you are looking for. The following displays exactly the same in Firefox 3 (mac) and IE7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <...
recognizing text inside an image is indeed a hot topic for researchers in that field, but only begun to grow out of control when [captcha's][1] became the "norm" in terms of defense against spam bots. Why use captcha's as protection? well because it is/was very hard to locate (and read) text inside an image! The rea...
How many DataContexts are appropriate?
|.net|asp.net|datacontext|database|linq-to-sql|visual-studio|
Are Multiple DataContext classes ever appropriate?
|.net|asp.net|visual-studio|database|linq-to-sql|datacontext|
In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary to create [DataContext][1] [classes][2] (which is usually done using the designer in VS 2008). From the UI perspective, the DataContext is a design of the sections of your database that you would like to expose to through LinqToSql and is in...
In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary to create [DataContext][1] [classes][2] (which is usually done using the designer in VS 2008). From the UI perspective, the DataContext is a design of the sections of your database that you would like to expose to through LinqToSql and is in...
CPU throttling in C++
|c++|cpu|throttling|
I was just wandering if there is an elegant way to set the maximum CPU load for a particular thread doing intensive calculations. Right now I have located the most time consuming loop in the thread (it does only compression) and use GetTickCount() and Sleep() with hardcoded values. It makes sure that the loop continues...
I can't think of any cross platform way of what you want (or any guaranteed way full stop) but as you are using GetTickCount perhaps you aren't interested in cross platform :) I'd use interprocess communications and set the intensive processes nice levels to get what you require but I'm not sure that's appropriate f...
The list [] is dynamic and flexible but that flexibility comes at a speed cost. The tupel () is fixed (immutable) and therefore faster.
The [list][1] [1,2,3] is dynamic and flexible but that flexibility comes at a speed cost. The [tuple][2] (1,2,3) is fixed (immutable) and therefore faster. EDIT: fixed spelling and added links to diveintopython.org [1]: http://diveintopython.org/native_data_types/lists.html [2]: http://diveintopython.org/n...
If you want lisp to look like Ruby use Ruby. It's possible to use Ruby (and Python) in a very lisp like way which is one of the main reasons they have gained acceptance so quickly.
@sparkes Sometimes LISP is the clear language choice, namely Emacs extensions. I'm sure I could use Ruby to extend Emacs if I wanted to, but Emacs was designed to be extended with LISP, so it seems to make sense to use it in that situation.
databinding in C# - any solution to the "illegal cross thread call" ?
|c#|data-binding|
<p>when you data bind in C#, the thread that changes the data causes the control to change too. but if this thread is not the one on which the control was created, youll get the above exceptions. </p> <p>surfed the net - no good answer. </p> <p>anyone ?</p>
Most Efficient Way to Test Object Type
|c#|.net|double|int|
I have values stored as strings in a DataTable where each value could really represent an int, double, or string (they were all converted to strings during an import process from an external data source). I need to test and see what type each value really is. What is more efficient for the application (or is there n...
<p>would use double.TryParse , has performance benefits.</p>
As I don't have a test case to go from I can't guarantee this solution, but it seems to me that a scenario similar to the one used to update progress bars in different threads (use a delegate) would be suitable here. public delegate void DataBindDelegate(); public DataBindDelegate BindData = new DataBindDel...
You should be able to do something like: if (control.InvokeRequired) { control.Invoke(delegateWithMyCode); } else { delegateWithMyCode(); } InvokeRequired is a property on Controls to see if you are on the correct thread, then Invoke will invoke the delegate on the c...
You should be able to do something like: if (control.InvokeRequired) { control.Invoke(delegateWithMyCode); } else { delegateWithMyCode(); } InvokeRequired is a property on Controls to see if you are on the correct thread, then Invoke will invoke the delegate on the c...
I'd personally use int.tryparse, then double.tryparse. Performance on those methods is quite fast. They both return a Boolean. If both fail then you have a string, per how you defined your data.
On linux, you can change the scheduling priority of a thread with nice().
I would say, don't worry so much about such micro performance. It is much better to just get something to work, and then make it as clear and concise and easy to read as possible. The worst thing you can do is sacrifice readability for an insignificant amount of performance. In the end, the best way to deal with p...
If the thread call is "illegal" (i.e. the DataBind call affects controls that were not created in the thread it is being called from) then you need to create a delegate so that even if the decision / preparation for the DataBind is not done in the control-creating thread, any resultant modification of them (i.e. DataBi...
This is more or less the perfect use case for [SVK][1]. SVK is a command line front end for subversion that works with an entire local copy of the repository. So your commits, updates, etc. work on the local repository and you can then sync with a master. I would generally recommend SVK over plain subversion anyway ...
One way of deciding whether or not to use nested classes is to think whether or not this class plays a supporting role or it's own part. If it exists solely for the purpose of helping another class then I generally make it a nested class. There are a whole load of caveats to that, some of which seem contradictory bu...
sounds like a case where you could use the [strategy pattern][1] [1]: http://en.wikipedia.org/wiki/Strategy_pattern
Also make sure you don't miss the [dnrTV webcast show][1] that Carl Franklin (the man behind .NET rocks) publishes. Even if it's a not a podcast and requires a more attention while watching it it's really informative and if you're into .NET and Microsoft related techniques you'll learn a lot. [1]: http://www.dnr...
Here is my own contribution for the [Java programming language][1]. first some code: public void swap(int x, int y) { int tmp = x; x = y; y = tmp; } calling this method will result in this: int pi = 3; int everything = 42; swap(pi, everything); ...
**by value** - is slower than by reference since the system has to copy the parameter - used for input only **by reference** - faster since only a pointer is passed - used for input **and** output - can be very dangerous if used in conjunction with global variables
I am pretty sure this is one of the things due to change in python 3.0 with perhaps bin() to go with hex() and oct(). At the moment AFAIK eval('01010101101') does what you'd expect it to. EDIT: checked eval appears to work correctly :)
I am pretty sure this is one of the things due to change in python 3.0 with perhaps bin() to go with hex() and oct(). At the moment AFAIK eval('01010101101') does what you'd expect it to. EDIT: checked eval appears to work correctly :) EDITED AGAIN: it does work, as long as you start with a magic '0' try i...
I am pretty sure this is one of the things due to change in python 3.0 with perhaps bin() to go with hex() and oct(). At the moment AFAIK eval('01010101101') does what you'd expect it to. EDIT: not working :) lbrandy's answer is correct in all cases.
I am pretty sure this is one of the things due to change in python 3.0 with perhaps bin() to go with hex() and oct(). EDIT: lbrandy's answer is correct in all cases.
Subversion makes it easy (some think too easy) to create a new branch using the svn copy command. $ svn copy svn+ssh://host.example.com/repos/project/trunk \ svn+ssh://host.example.com/repos/project/branch \ -m "Creating a branch of project"
I think you're looking for GetModuleFileName. [http://www.swissdelphicenter.ch/torry/showcode.php?id=143][1]: { If you are working on a DLL and are interested in the filename of the DLL rather than the filename of the application, then you can use this function: } function GetModuleN...
This looks like an excellent opportunity to have a look at Aspect Oriented Programming. Here is a good article on [AOP in .NET][1]. The general idea is that you'd extract the cross-functional concern (i.e. Retry for x hours) into a separate class and then you'd annotate any methods that need to modify their behaviour i...
Monitor a specific RSS
|rss|
For all the RSS feeds I subscribe to I use [Google Reader][1] which I love. I do however have a couple of specific RSS feeds that I'd like to be notified as soon as when they get updated (say for example a RSS feed for a forum I like to monitor and respond to as quick as possible). Are there any tools out there for...
You do the unit testing by mocking out the database connection. This way, you can build scenarios where specific queries in the flow of a method call succeed or fail. I usually build my mock expectations so that the actual query text is ignored, because I really want to test the fault tolerance of the method and how it...
In my experience with LINQ to SQL and LINQ to Entities a DataContext is synonymous to a connection to the database. So if you were to use multiple data stores you would need to use multiple DataContexts. My gut reaction is you wouldn't notice to much of a slow down with a DataContext that encompasses a large number of ...
Don't forget there is also **pass by name**, and **pass by value-result**. Pass by value-result is similar to pass by value, with the added aspect that the value is set in the original variable that was passed as the parameter. It can, to some extent, avoid interference with global variables. It is apparently bett...
The solution is to use the TempData property to store the desired Request components. For instance: public ActionResult Send() { TempData["form"] = Request.Form; return this.RedirectToAction(a => a.Form()); } Then in your "Form" action you can go: public Actio...
The solution is to use the TempData property to store the desired Request components. For instance: public ActionResult Send() { TempData["form"] = Request.Form; return this.RedirectToAction(a => a.Form()); } Then in your "Form" action you can go: public ActionRe...
The solution is to use the TempData property to store the desired Request components. For instance: public ActionResult Send() { TempData["form"] = Request.Form; return this.RedirectToAction(a => a.Form()); } Then in your "Form" action you can go: public ActionResult Form...